package com.example.yuejian21.nongfusanquan.yuejian21.model;

import com.example.yuejian21.nongfusanquan.yuejian21.base.RetrofitListener;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Collectclubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.UserCollectclubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.service.ClubService;
import com.example.yuejian21.nongfusanquan.yuejian21.service.CollectService;
import com.example.yuejian21.nongfusanquan.yuejian21.service.UserService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Nongfusanquan on 2017-10-12.
 */

public class Clubmodel {
    private Retrofit retrofit;

    public Clubmodel() {
        retrofit = new Retrofit.Builder()
                .baseUrl("http://10.0.2.2/yuejian14/index.php/API/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getClublist( final RetrofitListener listener) {
        ClubService showService = retrofit.create(ClubService.class);
        Call call = showService.getClublist();
        Callback<List<Clubbean>> callback = new Callback<List<Clubbean>>() {
            @Override
            public void onResponse(Call<List<Clubbean>> call, Response<List<Clubbean>> response) {
                List<Clubbean> data = response.body();
                listener.onSuccess(data);//userId这里有问题
            }

            @Override
            public void onFailure(Call<List<Clubbean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
//        public Call<List<Clubbean>> getClublist(){
//            ClubService clubService = retrofit.create(ClubService.class);
//            return clubService.getClublist();
//        }

    public Call<List<Clubbean>> getClubifo(){
        ClubService clubService = retrofit.create(ClubService.class);
        return clubService.getClubinfo();
    }

    //关注俱乐部
    public Call<Collectclubbean> CollectClub(int user_id, int club_id){
        CollectService collectionService=retrofit.create(CollectService.class);
        return collectionService.getCollectClub(user_id,club_id);
    }

    public Call<Collectclubbean> CheckClub(int user_id, int club_id){
        CollectService collectionService=retrofit.create(CollectService.class);
        return collectionService.CheckClub(user_id,club_id);
    }

    public Call<List<UserCollectclubbean>> getMyCollectlist(int user_id){
        UserService collectionService=retrofit.create(UserService.class);
        return collectionService.getMyCollectlist(user_id);
    }

    }

